import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:xiaomi_shop/app/api/api.dart';
import 'package:xiaomi_shop/app/services/screenAdapter.dart';
import 'package:xiaomi_shop/models/orderItemModel.dart';

import '../controllers/order_detail_controller.dart';

class OrderDetailView extends GetView<OrderDetailController> {
  const OrderDetailView({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('订单详情'),
        centerTitle: true,
      ),
      body: Container(
        color: Colors.grey.shade100,
        child: ListView(
          padding: EdgeInsets.all(ScreenAdapter.width(30)),
          children: [
            // 商品信息
            Card(
              color: Colors.white,
              elevation: 0,
              child: Padding(
                padding: EdgeInsets.all(ScreenAdapter.width(30)),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      "商品信息",
                      style: TextStyle(
                          fontSize: ScreenAdapter.fontSize(44),
                          fontWeight: FontWeight.bold),
                    ),
                    SizedBox(
                      height: ScreenAdapter.height(30),
                    ),
                    // 商品
                    Container(
                      margin: EdgeInsets.only(
                          top: ScreenAdapter.height(20),
                          bottom: ScreenAdapter.height(20)),
                      child: Column(
                        children: controller.orderModel.order_item!.map((e) {
                          OrderItemModel itemModel = e;
                          return Column(
                            children: [
                              Row(children: [
                                SizedBox(
                                  width: ScreenAdapter.width(160),
                                  height: ScreenAdapter.width(160),
                                  child: Image.network(
                                    "${Api.basicUrl}/${itemModel.product_img}",
                                    fit: BoxFit.cover,
                                  ),
                                ),
                                SizedBox(
                                  width: ScreenAdapter.width(20),
                                ),
                                Expanded(
                                  child: Text(itemModel.product_title!),
                                ),
                                Text("x${itemModel.product_count}")
                              ]),
                              SizedBox(
                                height: ScreenAdapter.height(20),
                              )
                            ],
                          );
                        }).toList(),
                      ),
                    ),
                  ],
                ),
              ),
            ),
            SizedBox(
              height: ScreenAdapter.height(30),
            ),
            // 订单信息
            Card(
              color: Colors.white,
              elevation: 0,
              child: Padding(
                padding: EdgeInsets.all(ScreenAdapter.width(30)),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      "订单信息",
                      style: TextStyle(
                          fontSize: ScreenAdapter.fontSize(44),
                          fontWeight: FontWeight.bold),
                    ),
                    SizedBox(
                      height: ScreenAdapter.height(20),
                    ),
                    ListTile(
                      title: Text("订单编号：${controller.orderModel.order_id}"),
                      contentPadding: EdgeInsets.all(0),
                    ),
                    ListTile(
                      title: Text(
                          "下单时间：${DateTime.fromMillisecondsSinceEpoch(controller.orderModel.add_time!.toInt(), isUtc: false)}"),
                      contentPadding: EdgeInsets.all(0),
                    ),
                    ListTile(
                      title: Text("支付方式：${controller.orderModel.order_id}"),
                      contentPadding: EdgeInsets.all(0),
                    ),
                    ListTile(
                      title: Text("支付时间：${controller.orderModel.order_id}"),
                      contentPadding: EdgeInsets.all(0),
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
